package com.eningqu.aipen.utils;

import android.content.Context;
import android.graphics.Point;
import android.os.Build;
import android.view.WindowManager;

import com.blankj.utilcode.util.Utils;
import com.eningqu.aipen.MyApplication;

/**
 * Package:com.eningqu.aipen.utils
 * Author:starr
 * Time:2024/1/26 14:26
 * Description: 获取屏幕信息工具类
 */
public class ScreenUtils {

    public static int getScreenWidth() {
        WindowManager wm = (WindowManager) Utils.getApp().getSystemService(Context.WINDOW_SERVICE);
        if (wm == null) {
            return -1;
        } else {
            Point point = new Point();
            if (Build.VERSION.SDK_INT >= 17) {
                wm.getDefaultDisplay().getRealSize(point);
            } else {
                wm.getDefaultDisplay().getSize(point);
            }

            return point.x;
        }
    }

    public static int getScreenHeight() {
        WindowManager wm = (WindowManager)Utils.getApp().getSystemService(Context.WINDOW_SERVICE);
        if (wm == null) {
            return -1;
        } else {
            Point point = new Point();
            if (Build.VERSION.SDK_INT >= 17) {
                wm.getDefaultDisplay().getRealSize(point);
            } else {
                wm.getDefaultDisplay().getSize(point);
            }

            return point.y;
        }
    }

    public static float getScreenDensity() {
        return MyApplication.mContext.getResources().getDisplayMetrics().density;
    }

    public static int getScreenDensityDpi() {
        return MyApplication.mContext.getResources().getDisplayMetrics().densityDpi;
    }
}
